import { Injectable, NotFoundException } from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service';
import { Prisma, course, user_course } from '@prisma/client';
@Injectable()
export class CourseService {
  constructor(private readonly prisma: PrismaService) { }
  getSentence() {
    return this.prisma.course.findMany({
      where: {
        isJz:1,
      },
      orderBy: {
        title: 'desc',
      }
    });
  }
  getCourse(courseTypeId: string, courseTypeKey: string) {
    let where = {} as Prisma.courseWhereInput;
    where = {
      ...where,
      isJz:0,
      typeId: courseTypeId,
    }
    if (courseTypeKey !== 'all') {
      where = {
        ...where,
        title: {
          contains: courseTypeKey,
          mode: 'insensitive',
        }
      }
    }
    return this.prisma.course.findMany({
      where: where,
      orderBy: {
        title: 'desc',
      }
    });
  }

  getCourseKey(keyword: string) {
    if (keyword === '') return;
    return this.prisma.course.findMany({
      where: {
        title: {
          contains: keyword,
          mode: 'insensitive',
        }
      },
      orderBy: {
        title: 'desc',
      }
    });
  }

  getCourseDetail(courseId: string) {
    return this.prisma.course.findUnique({
      where: {
        id: courseId,
      },
    }
    );
  }
}